package com.ck.print.demo.printbridge.message.handler;

import com.ck.print.demo.printbridge.PrintWebSocketClient;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Function;

public class MessageHandleChain {
    List<IMessageHandle<Map<String, Object>, Boolean>> handles = new ArrayList<>();

    public void add(IMessageHandle<Map<String, Object>, Boolean> handle) {
        handles.add(handle);
    }

    public void handle(Map<String, Object> message, PrintWebSocketClient currentClient, PrintWebSocketClient friendClient) {
        for (IMessageHandle<Map<String, Object>, Boolean> handle : handles) {
            if (handle.apply(message, currentClient, friendClient)) {
                break;
            }
        }
    }
}
